package com.woniu.apiBoss.service;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.woniu.internalcommon.dto.ForecastPriceDTO;
import com.woniu.internalcommon.dto.PriceRule;
import com.woniu.internalcommon.dto.ResponseResult;
import com.woniu.internalcommon.remote.ServicePriceClient;
import com.woniu.internalcommon.request.PriceRuleIsNewRequest;
import com.woniu.internalcommon.response.ForecastPriceResponse;
import com.woniu.internalcommon.response.PriceRulePage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author zcnovice
 * @data 2025/7/12 下午2:57
 */
@Service
public class ApiPriceRuleService {


    @Autowired
    private ServicePriceClient servicePriceClient;


    public ResponseResult add(PriceRule priceRule){
        ResponseResult add = servicePriceClient.add(priceRule);
        return add;
    }



    public ResponseResult edit(PriceRule priceRule){
        ResponseResult edit = servicePriceClient.edit(priceRule);
        return edit;
    }


    /* 传入一个String类型的版本编号，根据这个版本编号fare_type(String)  查询fare_version(int)最高的版本 */
    public ResponseResult<PriceRule> getNewestVersion(String fareType){
        ResponseResult<PriceRule> newestVersion = servicePriceClient.getNewestVersion(fareType);
        return newestVersion;
    }


    /* 判断规则是不是最新的 */
    public ResponseResult<Boolean> isNew(PriceRuleIsNewRequest priceRuleIsNewRequest){

        ResponseResult<Boolean> isNew = servicePriceClient.isNew(priceRuleIsNewRequest);
        return isNew;
    }

    /* 判断改城市与车型计价规则是否存在 */
    public ResponseResult<Boolean> ifExists(String cityCode,String vehicleType){
        ResponseResult<Boolean> ifExists = servicePriceClient.ifExists(cityCode,vehicleType);
        return ifExists;
    }


    public ResponseResult<ForecastPriceResponse> forecast(ForecastPriceDTO forecastPriceDTO){
        ResponseResult<ForecastPriceResponse> forecast = servicePriceClient.forecast(forecastPriceDTO);
        return forecast;
    }

    public ResponseResult<Double> calculatePrice(Integer distance, Integer duration, String cityCode, String vehicleType){
        ResponseResult<Double> calculatePrice = servicePriceClient.calculatePrice(distance, duration, cityCode, vehicleType);
        return calculatePrice;
    }

    public ResponseResult<Page<PriceRule> > query(PriceRulePage priceRulePage){
        if(priceRulePage.getCurrent() == null || priceRulePage.getCurrent() < 1) priceRulePage.setCurrent(1);
        if(priceRulePage.getSize() == null || priceRulePage.getSize() < 1) priceRulePage.setSize(10);

        ResponseResult<Page<PriceRule>> query = servicePriceClient.query(priceRulePage);
        return query;
    }

    public ResponseResult delete(Long Id){
        ResponseResult delete = servicePriceClient.delete(Id);
        return delete;
    }

}
